package com.cloudcc.mobile.view.fragment;

import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.util.Base64;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.cloudcc.cloudframe.bus.EventEngine;
import com.cloudcc.cloudframe.bus.MenuToggleEventR;
import com.cloudcc.cloudframe.bus.MessageNumX;
import com.cloudcc.cloudframe.net.ErrorInfo;
import com.cloudcc.cloudframe.net.RequestListener;
import com.cloudcc.cloudframe.net.ResultCallBack;
import com.cloudcc.cloudframe.ui.viewgroup.CustomViewpager;
import com.cloudcc.cloudframe.ui.viewgroup.LazyViewPager;
import com.cloudcc.cloudframe.util.GsonUtil;
import com.cloudcc.cloudframe.util.ListUtils;
import com.cloudcc.cloudframe.util.StringUtils;
import com.cloudcc.mobile.AppContext;
import com.cloudcc.mobile.ExtraConstant;
import com.cloudcc.mobile.R;
import com.cloudcc.mobile.ReceiverConstant;
import com.cloudcc.mobile.adapter.BeauInfoAboutAdapter;
import com.cloudcc.mobile.adapter.DynamicAdapter;
import com.cloudcc.mobile.adapter.RelevantChatAdatper;
import com.cloudcc.mobile.adapter.RelevantPopAdapter;
import com.cloudcc.mobile.bull.ShopAddressActivity;
import com.cloudcc.mobile.dao.BeauInfoWeiTieDao;
import com.cloudcc.mobile.dao.impl.BeauInfoShareSet;
import com.cloudcc.mobile.dao.impl.ChatterEngineImpl;
import com.cloudcc.mobile.dialog.BeauInfoFastRecordDialog;
import com.cloudcc.mobile.entity.beau.BeauInfoEntity;
import com.cloudcc.mobile.entity.beau.BeauInfoEntity.ObjMenu;
import com.cloudcc.mobile.entity.beau.BeauInfoEntity.ObjRelation;
import com.cloudcc.mobile.entity.beau.BeauInfoEntity.TabLabel;
import com.cloudcc.mobile.entity.beau.BeauInfoTabEntity;
import com.cloudcc.mobile.entity.chatter.ChatterEventType;
import com.cloudcc.mobile.event.BeauEventList;
import com.cloudcc.mobile.event.BeauEventList.BeauInfoEvent;
import com.cloudcc.mobile.event.BeauEventList.BeauInfoEventnew;
import com.cloudcc.mobile.event.BeauEventList.DynamicListEvent;
import com.cloudcc.mobile.event.refresh.RefreshEntiityListEvent;
import com.cloudcc.mobile.manager.CacheManager;
import com.cloudcc.mobile.manager.RunTimeManager;
import com.cloudcc.mobile.manager.UrlManager;
import com.cloudcc.mobile.presenter.BeauPresenter;
import com.cloudcc.mobile.presenter.OtherPresenter;
import com.cloudcc.mobile.util.PopuWindowUtils;
import com.cloudcc.mobile.util.SystemUtils;
import com.cloudcc.mobile.util.ViewUtils;
import com.cloudcc.mobile.view.activity.BeauInfoActivity;
import com.cloudcc.mobile.view.activity.BeauLitterListActivity;
import com.cloudcc.mobile.view.activity.CreateMultipleListActivity;
import com.cloudcc.mobile.view.activity.EditorActivity;
import com.cloudcc.mobile.view.activity.MapsActivity;
import com.cloudcc.mobile.view.activity.NewContact;
import com.cloudcc.mobile.view.activity.NewMoreActivity;
import com.cloudcc.mobile.view.activity.NewMoreForAssetsActivity;
import com.cloudcc.mobile.view.activity.NewSelectActivity;
import com.cloudcc.mobile.view.activity.TaskManagementHistoryActivty;
import com.cloudcc.mobile.view.base.BaseFragment;
import com.cloudcc.mobile.view.base.BaseWebViewFragment;
import com.cloudcc.mobile.view.dynamic.dynamic.DynamicFragment;
import com.cloudcc.mobile.view.main.MainUIActivity;
import com.cloudcc.mobile.view.market.MarketActivityInfoActivity;
import com.cloudcc.mobile.view.web.CloudWebViewActivity;
import com.cloudcc.mobile.view.web.NewWebView;
import com.cloudcc.mobile.view.web.NewWebViewActivity;
import com.cloudcc.mobile.view.web.WebSyncDefaultProxy;
import com.cloudcc.mobile.view.web.WebSyncDefaultProxy.MonitorParam;
import com.cloudcc.mobile.weight.EmptyLayout;
import com.cloudcc.mobile.widget.CloudCCTitleBar;
import com.cloudcc.mobile.widget.CloudCCTitleBar.OnTitleBarClickListener;
import com.easemob.chat.EMChat;
import com.google.gson.JsonObject;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import com.litesuits.android.log.Log;
import com.mypage.bean.EventData;
import com.mypage.model.PostShare;
import com.mypage.utils.AnimViewUtils;
import com.mypage.utils.SaveTemporaryData;
import com.mypage.utils.Utils;
import com.mypage.utils.VoiceMediaManager;
import com.mypage.view.activity.beautMore.BusinChangeActivity;
import com.mypage.view.activity.beautMore.ConvertCustomersActivity;
import com.mypage.view.activity.editpicture.PictureUtils;
import com.mypage.view.activity.picutils.DrawAct;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import Decoder.BASE64Decoder;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author wangzhiqiang
 * @Description: TODO()
 * @date 2015-11-19 下午4:00:53
 */
public class BeauInfoFragment extends BaseFragment implements
        OnCheckedChangeListener, OnTitleBarClickListener, BeauInfoShareSet.BeauInfoShareDao, BeauInfoShareSet.BeauInfoGenggaiJilu {
    protected WebView mmebView;
    public String mPname;
    public String mUrls;
    @Bind(R.id.layoutBack)
    RelativeLayout layoutBack;

    /**
     * by lyj 2017-07-20
     */
    private String OwnerName;
    private String OwnerId;

    @Bind(R.id.layoutTop)
    FrameLayout layoutTop;
    @Bind(R.id.toastHintContents)
    TextView toastHintContent;
    @Bind(R.id.imgDeletess)
    ImageView imgDeletess;
    private Map<String, String[]> mEntityTypes;
    @Bind(R.id.beau_name)
    TextView beau_name;
    @Bind(R.id.beau_name_sub)
    TextView beau_name_sub;
    //    @Bind(R.id.beau_location)
//    ImageView beau_location;
//    @Bind(R.id.beau_call)
//    ImageView beau_call;
//    @Bind(R.id.beau_email)
//    ImageView beau_email;
//    @Bind(R.id.beau_locationll)
//    LinearLayout beau_locationll;
    @Bind(R.id.beau_callll)
    LinearLayout beau_callll;
    @Bind(R.id.beau_zhuanhuan)
    LinearLayout beau_zhuanhuan;
    @Bind(R.id.beau_fenxiang)
    LinearLayout beau_fenxiang;

    //    @Bind(R.id.beau_emailll)
//    LinearLayout beau_emailll;
    //相应区域
    @Bind(R.id.xiangyingquyu)
    LinearLayout xiangyingquyu;


    public String from = "iss";
    public String callLog = null;
    public String names = null;
    public String mShiJian = "isa";
    @Bind(R.id.beau_detail)
    TextView beau_detail;

    // ListView mListView;

    @Bind(R.id.container)
    LinearLayout mContainer;

    @Bind(R.id.beau_information)
    LinearLayout beau_information;
    @Bind(R.id.footer_cooperation_icon)
    ImageView footer_cooperation_icon;
    @Bind(R.id.footer_cooperation_text)
    TextView footer_cooperation_text;

//    @Bind(R.id.relevent_dibu)
//    RelativeLayout relevent_dibu;

//    @Bind(R.id.context_text)
//    EditText context_text;

    @Bind(R.id.headerbar)
    CloudCCTitleBar headerbar;

    @Bind(R.id.radiogroup)
    RadioGroup radiogroup;

    @Bind(R.id.viewpager)
    CustomViewpager mViewPager;
//    @Bind(R.id.relevant_fasong)
//    ImageView relevant_fasong;

    @Bind(R.id.kuaisujilu)
    LinearLayout kuaisujilu;
    @Bind(R.id.tianjiahuodong)
    LinearLayout tianjiahuodong;
    @Bind(R.id.bianji)
    LinearLayout bianji;
    //    @Bind(R.id.fenxiang)
//    LinearLayout fenxiang;
    @Bind(R.id.gengduo)
    LinearLayout gengduo;
    @Bind(R.id.menu_foot)
    LinearLayout menu_foot;
    @Bind(R.id.beau_info_image)
    ImageView beauInfoImage;
    @Bind(R.id.beau_info_check_line)
    View checkLine;

    private int i = 0;
    private String mEns = RunTimeManager.getInstance().getlanguage();
    // @Bind(R.id.rv1)
    // RecyclerView mRe;
    public ViewPager mmViewPager;
    private List<View> viewPagerList = new ArrayList<View>();// GridView作为一个View对象添加到ViewPager集合中
    private int totalPage; // 总的页数
    private int mPageSize = 4; // 每页显示的最大的数量
    private ImageView[] ivPoints;// 小圆点图片的集合
//    private LinearLayout group;// 圆点指示器

    private BeauPresenter mBeauPresenter = new BeauPresenter();
    //第一个接口
    private BeauInfoEntity mBeauInfo1;
    //第二个接口
    private BeauInfoEntity mBeauInfo2;
    //默认显示Tab页面
    private BeauInfoTabEntity mBeauInfo3;
    //现实权限记录类型（更改所有人和更改记录类型的按钮）
    private BeauInfoEntity mBeauInfo4;

    private DynamicFragment mDynamicFragment;
    private MyDetailWeb mDetailFragment;
    // private NewEvent mNewEvent;
    private AboutFragment aboutEvent;
    private LinearLayout.LayoutParams lp;
    private LinearLayout layout;
    private String name;
    private File photoFile;
    //    public int isnum = 0;
    public String mPersionName;
    public String mPersionNameIds;
    public String mTiles;
    public String mJiLuName;
    public String ObjId;
    public int length1, length2, length3; // 2:跟踪记录  3 ：详情  1 : 相关
    private String checkviewpager = "0001";
    String listTitleName;
    /**
     * 活动相关的
     */
    public EventData eventData;
    //快速记录相关显示
//    public boolean isxianshi = true;
    //判断是否刷新
    public boolean isresum = true;

    private int currentIndex = 0;// 记录当前位置
    private float lineWidth;// 线的长度

    private List<ObjRelation> relationList;//相关列表信息

    private RelevantChatAdatper viewPagerAdapter;
    private Handler handler;

    /**
     * 语音相关的
     */
    public TextView ceshisss;
    public String mVoiceTimeLength;
    public String mVoiceBaseCode;
    public String mType = "amr";
    public String mName;
    public String mData;
    public String voiceId;
    public String returnCode;
    public String chatter;
    private AlphaAnimation appearAnimator;
    private AlphaAnimation appearAnimator2;
    private AlphaAnimation disappearAnimator;
    private AlphaAnimation disappearAnimator2;
    public int ts = 3000;
    public int ats = 3300;
    public boolean Booappear = true;
    private String  shopName,shopId;

    public BeauInfoFastRecordDialog dialog;

    /**
     * 电话
     */
    public boolean isCall = false;
    public boolean isPermission = false;

    //判断是否是营销资产
    public boolean isAssets = false;


    @Bind(R.id.message_num_tz)
    TextView message_num_tz;
    @Bind(R.id.message_num_99)
    TextView message_num_99;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        SaveTemporaryData.mSmart = "";
        onShowLoadingDialog();
        initAppear();
        ButterKnife.bind(this, super.onCreateView(inflater, container, savedInstanceState));
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    public void initAppear() {
        String DCIMCamera_PATH = Environment.getExternalStorageDirectory() + "/DCIM/Camera/";
        String name = "lyj" + ".jpg";
        File file = new File(DCIMCamera_PATH, name);
        if (!file.exists()) {
            file.mkdirs();
        }

        appearAnimator = new AlphaAnimation(0, 1);
        appearAnimator.setDuration(ts);
        appearAnimator2 = new AlphaAnimation(0, 1);
        appearAnimator2.setDuration(ts);
        disappearAnimator = new AlphaAnimation(1, 0);
        disappearAnimator.setDuration(ts);
        disappearAnimator2 = new AlphaAnimation(1, 0);
        disappearAnimator2.setDuration(ats);
    }

    @OnClick(R.id.imgDeletess)
    public void imgDeletess() {

        layoutTop.setVisibility(View.GONE);
//        setHintToast();
    }

    @Override
    public void init() {
        initViews();
        initListener();
        initHeightScreen();
        initHeader();
        initEntityMap();
        EventEngine.register(this);
        initContainer();
        registerDynamicRefreshReceiver();// 注册刷新监听
        radiogroup.setOnCheckedChangeListener(this);
        initViewPager();
        initReceiver();
        initChatterEventTypes();

        //第一次进来默认进入选中界面
        mBeauPresenter.getBeauTabInfo(mEntityId, mEntityNameID);

    }

    @Override
    public int getLayoutId() {
        return R.layout.beau_info_layout;
    }

    public void initViews() {
        handler = new Handler();
        BeauInfoShareSet.getInstance().addBeauInfoShare(this);
        BeauInfoShareSet.getInstance().addBeauInfoChange(this);
        DisplayMetrics dm = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
        int screenWidth = dm.widthPixels;
        lineWidth = screenWidth / 3;

        dialog = new BeauInfoFastRecordDialog(getActivity(), R.style.DialogLoadingTheme);

        beau_info_edit_web.setVisibility(View.GONE);
        setHeight(600);

        shopName = getArguments().getString("beau.name", "");
        shopId = getArguments().getString("web", "");
        if ("".equals(shopId)) {
            shopId = getArguments().getString("beau.id", "");
        }
        if("门店".equals(shopName)){
            footer_cooperation_text.setText("门店位置上传");
            footer_cooperation_icon.setImageResource(R.drawable.find_location_pressed);
        }

        isAssets = getArguments().getBoolean("isAssets",false);

    }

    private boolean mJudge = false;

    private int editHeight = 0;
    private int pingmuHeight = 0;
    private int jianpanHeight = 0;
    boolean isdibu = false;

    public void initListener() {

        xiangyingquyu.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                isdibu = false;
                return false;
            }
        });

        kuaisujilu.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {

                setRadioBtnb();

                dialog.show();
                dialog.setdata(mBeauInfo1, mEntityId);
                SaveTemporaryData.mBeauInfoTui = "No";
            }
        });
        tianjiahuodong.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                setRadioBtnb();
                if (mViewPager.getCurrentItem() != 0) {
                    mViewPager.setCurrentItem(0);
                    topBarChange(0);
//					setButtomUI(false);
                }
                List<String> list = fillEventTypes();
                Intent intent = new Intent(mContext, NewSelectActivity.class);
                Bundle menusend = new Bundle();
                menusend.putSerializable("Leftlist", (Serializable) list);
                menusend.putString("mEntityId", mEntityId);
                menusend.putString("mEntityNameID", mEntityNameID);
//				menusend.putSerializable("mBeauInfo", (Serializable) mBeauInfo);
                menusend.putString("jsonname", jsonname);
                intent.putExtras(menusend);
                mContext.startActivity(intent);
            }
        });
        bianji.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if("门店".equals(shopName)){
                    Intent intent=new Intent(mContext, ShopAddressActivity.class);
                    intent.putExtra("id",shopId);
                    startActivity(intent);
                    return;
                }
                i = 2;
                Intent intent = new Intent(mContext, CloudWebViewActivity.class);
                MonitorParam monitorParam = new MonitorParam(new String[]{"m=save",
                        "m=edit"}, WebSyncDefaultProxy.STEP_START,
                        new String[]{"/WeiXin_index.action"}, true,
                        WebSyncDefaultProxy.STEP_OVERRIDEURL);
                intent.putExtra(
                        "callback",
                        WebSyncDefaultProxy
                                .creatDefaultProxy(ReceiverConstant.RECEIVE_REFRESH)
                                .addMonitorParam(monitorParam).addHomeMonitor());
                if (StringUtils.equalsIgnoreCase(mEntityNameID, "attachement")) {
                    intent.putExtra(
                            ExtraConstant.EXTRA_URL,
                            UrlManager.getManager().addReturnUrl(
                                    UrlManager.getManager().getEntityDetailEditUrl1(
                                            mEntityId)));
                    startActivity(intent);
                } else {
                    intent.putExtra(
                            ExtraConstant.EXTRA_URL,
                            UrlManager.getManager().addReturnUrl(
                                    UrlManager.getManager().getEntityDetailEditUrl(
                                            mEntityId)));
                    startActivity(intent);
                }


            }
        });
        beau_fenxiang.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                setRadioBtna();
                if (mViewPager.getCurrentItem() != 1) {
                    mViewPager.setCurrentItem(1);
                    topBarChange(1);
                }
                if (mmebView != null) {
                    setShare();
                } else {
                    setShare();
                }
            }
        });
        gengduo.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent;
                Bundle menusend = new Bundle();
                if(isAssets)
                {
                    intent= new Intent(mContext, NewMoreForAssetsActivity.class);
                    menusend.putString("listTitle",listTitleName);
                }
                else {
                    intent = new Intent(mContext, NewMoreActivity.class);
                }

                menusend.putString("mPersionName", mPersionName);
                menusend.putString("mPersionNameIds", mPersionNameIds);

                menusend.putString("mPname", mPname);
                menusend.putString("mObjId", mObjId);
                menusend.putString("mObjName", mObjName);
                menusend.putString("mEntityId", mEntityId);
                menusend.putString("mEntityNameID", mEntityNameID);
                menusend.putBoolean("beau.ismefollow", isMeFollow);
                menusend.putString("mShiJian", mShiJian);
                menusend.putString("from", from);
                menusend.putString("jsonname", jsonname);
                if (mBeauInfo2 != null) {
                    menusend.putSerializable("mBeauInfo.relationCreateUrl", (Serializable) mBeauInfo2.relationCreateUrl);
                }
                if (mBeauInfo4 != null) {
                    menusend.putSerializable("mBeauInfo.recordIdButton", (Serializable) mBeauInfo4.recordIdButton);
                }
                if (mBeauInfo1 != null) {
                    menusend.putSerializable("mBeauInfo.tabLabel", (Serializable) mBeauInfo1.tabLabel);
                }
                intent.putExtras(menusend);
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public void share() {
        setRadioBtna();
        if (mViewPager.getCurrentItem() != 1) {
            mViewPager.setCurrentItem(1);
            topBarChange(1);
        }
        if (mmebView != null) {
            setShare();
        } else {
            setShare();
        }
    }

    @Override
    public void changeLei(String str) {
        if (!"".equals(str) && !"保存成功".equals(str)) {
            i = 2;
//            refreshInfoData();
            layoutTop.setVisibility(View.VISIBLE);
            layoutBack.setVisibility(View.GONE);
            toastHintContent.setText(str);
            new AnimViewUtils().appearToast(layoutBack);

        }

    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }


    /**
     * 初始化获取屏幕高度
     */
    public void initHeightScreen() {
        final DisplayMetrics displayMetrics = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay()
                .getMetrics(displayMetrics);
        final int height = displayMetrics.heightPixels; // 获取手机高度

    }

    private void initEntityMap() {
        mEntityTypes = new HashMap<String, String[]>();
        // Contact Opportunity Lead Account
        String[] contactKeys = mContext.getResources().getStringArray(
                R.array.entity_type_contact);//联系人
        String[] opportunityKeys = mContext.getResources().getStringArray(
                R.array.entity_type_opportunity);//业务机会
        String[] leadKeys = mContext.getResources().getStringArray(
                R.array.entity_type_lead);//潜在客户
        String[] accountKeys = mContext.getResources().getStringArray(
                R.array.entity_type_account);//客户
        String[] shichangKeys = mContext.getResources().getStringArray(
                R.array.entity_type_shichang);//市场活动
        String[] hetongKeys = mContext.getResources().getStringArray(
                R.array.entity_type_hetong);//合同
        String[] otherKeys = mContext.getResources().getStringArray(
                R.array.entity_type_other);
        mEntityTypes.put("003", contactKeys);
        mEntityTypes.put("002", opportunityKeys);
        mEntityTypes.put("004", leadKeys);
        mEntityTypes.put("001", accountKeys);
        mEntityTypes.put("other", otherKeys);
        mEntityTypes.put("006", shichangKeys);
        mEntityTypes.put("007", hetongKeys);
        for (int i = 0; i < contactKeys.length; i++) {
            String string = contactKeys[i];
            Log.d("sbdata1", string);
        }
    }

    String contexteditold = null;
    String contexteditnew = null;

    /**
     * 初始化标题
     */
    private void initHeader() {
        title = getArguments().getString("beau.name", "");
        mObjId = getArguments().getString("OBJID");
        mObjName = getArguments().getString("OBJNAME");
        mTiles = title;
        Log.d("liuyongjie", title);
        mEntityId = getArguments().getString("web", "");
        if ("".equals(mEntityId)) {
            mEntityId = getArguments().getString("beau.id", "");
        }
        try {
//            isnum = getArguments().getInt("isnum");
            from = getArguments().getString("from", "");
            callLog = getArguments().getString("callLog", "");
            mShiJian = getArguments().getString("matters", "");
            String sss = mShiJian;
        } catch (Exception e) {
            // TODO: handle exception
        }
        chatter = getArguments().getString("chatter", "");
        mEntityNameID = getArguments().getString("beau.nameid", "");
        names = getArguments().getString("beau.name", "");
        ImageID = getArguments().getString("beau.imageid", "");
        isMeFollow = getArguments().getBoolean("beau.ismefollow", false);
        headerbar.setTitle(title);
        headerbar.setOnTitleBarClickListener(this);
        headerbar.setRightImageResource(R.drawable.lingdang);
        if (callLog != null && callLog.length() != 0) {
//            headerbar.setmLeftText(null);
            if (callLog.equals("addphone")) {
                String startTime = getArguments().getString("startTime", "");
                String endTime = getArguments().getString("endTime", "");
                String relevantName;
                try {
                    relevantName = names + getString(R.string.beau_info_fragment_phone);
                    AppContext.relevantName = names;
                } catch (Exception e) {
                    relevantName = names;
                    e.printStackTrace();
                }
                String reuevantType = names;
                String key = "1";
                Intent intent = new Intent(getActivity(), EditorActivity.class);
                intent.putExtra("urlId", mEntityId);
                intent.putExtra("key", key);
                intent.putExtra("CustomerActivity", relevantName);
                intent.putExtra("reuevantType", getString(R.string.beau_info_fragment_phone_activity));
                intent.putExtra("name", names);
                intent.putExtra("startTime", startTime);
                intent.putExtra("endTime", endTime);
                intent.putExtra("from", "calllog");
                startActivity(intent);
            }
        }

        setImage(ImageID);
    }

    /**
     * 初始化 viewpager
     */
    private void initViewPager() {
//        ViewTreeObserver vto = mViewPager.getViewTreeObserver();

        mDynamicFragment = new MyDynamicFragment();
        aboutEvent = new AboutFragment();
        // sdsds
        mDetailFragment = new MyDetailWeb();
        // 赋值
        mDynamicFragment.requestData();
        ArrayList<Fragment> views = new ArrayList<Fragment>();
        views.add(mDynamicFragment);
        views.add(mDetailFragment);
        views.add(aboutEvent);
        // mViewPager.setFocusable(true);
        mViewPager.setOnPageChangeListener(new LazyViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if (position == 0) {
                    topBarChange(0);
                    RadioButton b = (RadioButton) findViewById(R.id.beau_genzong);
                    b.setChecked(true);
                    setHeight(length2);
                }
                if (position == 1) {
                    topBarChange(1);
                    RadioButton b = (RadioButton) findViewById(R.id.beau_detail);
                    b.setChecked(true);
                    setHeight(length3);
                }
                if (position == 2) {
                    RadioButton b = (RadioButton) findViewById(R.id.beau_about);
                    topBarChange(2);
                    b.setChecked(true);
                    setHeight(length1);
                }

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        if (viewPagerAdapter == null) {
            viewPagerAdapter = new RelevantChatAdatper(
                    getActivity().getSupportFragmentManager(), views);
            mViewPager.setAdapter(viewPagerAdapter);
            mViewPager.hasSetTouchMode = true;
            mViewPager.setOffscreenPageLimit(2);
        }

    }

    private void setImage(String imageid){
        try {
            Class drawable = R.drawable.class;
            Field field = drawable.getField(imageid + "_88");
            int id = field.getInt(field.getName());
            beauInfoImage.setImageBitmap(null);
            beauInfoImage.setBackgroundResource(id);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }

    private MyReceiver mDynamicRefreshReceiver;

    private void registerDynamicRefreshReceiver() {
        mDynamicRefreshReceiver = new MyReceiver();
        IntentFilter filter = new IntentFilter();
        filter.addAction(AppContext.INDEXADAPTER_SHUAXIN);
        filter.addAction(AppContext.RECORD_ID_CHANGED_SHUAXIN);
        mContext.registerReceiver(mDynamicRefreshReceiver, filter);
    }

    private class MyReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals(AppContext.INDEXADAPTER_SHUAXIN)
                    || action.equals(AppContext.RECORD_ID_CHANGED_SHUAXIN)) {
                if (mDynamicFragment != null && mDynamicFragment.isResumed()) {
                    mDynamicFragment.onRefreshData();
                }
            }
        }
    }

    /**
     * 云帖  也就是 跟踪记录
     *
     * @author wangzhiqiang
     * @Description: 子类
     * @date 2015-12-14 下午8:08:57
     */
    public class MyDynamicFragment extends DynamicFragment {

        private EmptyLayout empty_loading;

        // private LinearLayout layout;
        @Override
        public void init() {
            BeauInfoWeiTieDao.getInstance().addBeauInfoweiTie(new BeauInfoWeiTieDao.BeauInfoWeiTie() {
                @Override
                public void WeiTieSuccess() {
                    requestData();
                }
            });

            mRefreshLayout.setEnabled(false);
            initLoadMore();
            mListView.setBackgroundColor(Color.parseColor("#57F2F8F8"));
            mAdapter = new DynamicAdapter(mContext);
            mListView.setAdapter(mAdapter);
            mAdapter.setOnItemtListener(this);

            if (empty_loading == null) {
                empty_loading = new EmptyLayout(mContext);
                empty_loading.setLayoutParams(new LayoutParams(
                        LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
                ViewUtils.addListViewEmptyView(mContext, mListView, empty_loading);
            }
        }

        @Override
        public String getQueryType() {
            return "";
        }

        @Override
        public void requestData() {
            mControl.getDynamicsAboutRecord(currentPage, mEntityId);
        }

        @Override
        public int getLayoutId() {
            return super.getLayoutId();
        }

        public void onEventMainThread(DynamicListEvent event) {
            if ((event.isError() && isFromRefresh())
                    || (ListUtils.isEmpty(event.getData()) && isFromRefresh())) {// 加载数据为空
                length2 = 600;
                empty_loading.empty();
                if (mAdapter != null) {
                    mAdapter.clear();
                }
                return;
            }
            if (isFromRefresh()) {
                mAdapter.changeData(event.getData());
            } else {
                mAdapter.addData(event.getData());
            }
            if (event.getData().size() > 0 && mAdapter != null) {
                length2 = 0;
                for (int i = 0; i < mAdapter.getCount(); i++) {
                    View view = mAdapter.getView(i, null, mListView);
                    view.measure(0, 0);
                    length2 = length2 + view.getMeasuredHeight() + mListView.getDividerHeight();
                }
            }
            length2 = length2 + 200;
            if (mViewPager.getCurrentItem() == 0) {
                setHeight(length2);
            }
        }

        @Override
        protected void onRequestFinish(boolean dataIsEmpty) {
            mLoadMoreLayout.loadMoreFinish(false, true);
        }

        @Override
        protected void initRequestData() {
            // 禁止自动刷新
        }

        @Override
        public void onResume() {
            super.onResume();
            if (mViewPager.getCurrentItem() == 0) {
                Intent intent = new Intent(AppContext.INDEXADAPTER_SHUAXIN);
                mContext.sendBroadcast(intent);
            }
        }


    }

    /**
     * 这是相关界面
     *
     * @author liuyongjie
     */
    public class AboutFragment extends Fragment {

        private ListView aboutlistView;
        private BeauInfoAboutAdapter aboutadapter;
        private EmptyLayout empty_loading;

        @Override
        public View onCreateView(LayoutInflater inflater,
                                 @Nullable ViewGroup container,
                                 @Nullable Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            View view = View.inflate(getActivity(), R.layout.beau_info_about_fragment, null);
            aboutlistView = (ListView) view
                    .findViewById(R.id.beau_info_about_listview);

            empty_loading = new EmptyLayout(mContext);
            empty_loading.setLayoutParams(new LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
            empty_loading.loading();
            ViewUtils.addListViewEmptyView(mContext, aboutlistView, empty_loading);

            aboutadapter = new BeauInfoAboutAdapter(getActivity());
            aboutlistView.setAdapter(aboutadapter);

            aboutlistView.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    ObjRelation objRelation = relationList.get(position);
                    if (StringUtils.equals("bde", objRelation.prefix)) {// 字段跟踪历史
                        // Log.d("tiaozhuan",
                        // "跳转到活动历史"+objRelation.relationName);
                        Intent intent = new Intent(mContext,
                                BeauLitterListActivity.class);
                        intent.putExtra("name", objRelation.relationName);
                        intent.putExtra("layoutId", objRelation.layoutId);
                        intent.putExtra("recordId", mEntityId);
                        intent.putExtra("relatedlistId",
                                objRelation.relatedlistId);
                        startActivity(intent);
                    } else if (StringUtils.equals("abe", objRelation.prefix)) {// 审批历史
                        Intent intent = new Intent(mContext,
                                TaskManagementHistoryActivty.class);
                        intent.putExtra("relatedId", mEntityId);
                        intent.putExtra("title", objRelation.relationName);
                        startActivity(intent);
                    } else if (StringUtils.equals("opt", objRelation.prefix)) {
                        //业务机会小组
                        Intent intent = new Intent(mContext, BusinChangeActivity.class);
                        intent.putExtra("mPersionName", mPersionName);
                        intent.putExtra("layoutId", objRelation.layoutId);
                        intent.putExtra("recordId", mEntityId);
                        intent.putExtra("relatedlistId", objRelation.relatedlistId);
                        intent.putExtra("prefix", objRelation.prefix);
                        startActivity(intent);
                    }//联系人角色
                    else if (StringUtils.equals("ocr", objRelation.prefix)) {
                        Intent intent = new Intent(mContext,
                                NewContact.class);
                        intent.putExtra("layoutId", objRelation.layoutId);
                        intent.putExtra("recordId", mEntityId);
                        intent.putExtra("relatedlistId", objRelation.relatedlistId);
                        startActivity(intent);
                    } else {
                        Intent intent = new Intent(mContext,
                                CreateMultipleListActivity.class);
                        intent.putExtra("name", objRelation.relationName);
                        intent.putExtra("listTitle", listTitleName);
                        intent.putExtra("beau.name", title);
                        intent.putExtra("beau.nameid", mEntityNameID);
                        intent.putExtra("layoutId", objRelation.layoutId);
                        intent.putExtra("recordId", mEntityId);
                        intent.putExtra("relatedlistId",
                                objRelation.relatedlistId);
                        intent.putExtra("prefix", objRelation.prefix);
                        intent.putExtra("beau.ismefollow", isMeFollow);
                        intent.putExtra("beau.num", objRelation.relationSize);
                        intent.putExtra("imagenum", position);
                        List<ObjMenu> objMenulist = new ArrayList<ObjMenu>();
                        if (mBeauInfo2 != null) {
                            for (int i = 0; i < mBeauInfo2.relationCreateUrl
                                    .size(); i++) {
                                ObjMenu obj = mBeauInfo2.relationCreateUrl
                                        .get(i);
                                Log.d("ObjMenu", obj.relatedlistId + "shenme"
                                        + " " + objRelation.relatedlistId
                                        + "zhege");
                                if (objRelation.relatedlistId
                                        .equals(obj.relatedlistId)) {
                                    objMenulist.add(obj);
                                }
                            }
                        }
                        intent.putExtra("objMenulist",
                                (Serializable) objMenulist);
                        startActivity(intent);
                    }

                }
            });
            return view;
        }

        public void loadview() {
            if (relationList != null && aboutadapter != null) {
                aboutadapter.clear();
                aboutadapter.notifyDataSetChanged();
                aboutadapter.addData(relationList);
                length1 = 0;
                for (int i = 0; i < aboutadapter.getCount(); i++) {
                    View view = aboutadapter.getView(i, null, aboutlistView);
                    view.measure(0, 0);
                    length1 = length1 + view.getMeasuredHeight();
                }
            } else {
                length1 = 600;
                empty_loading.empty();
            }
            if (mViewPager.getCurrentItem() == 2) {
                setHeight(length1);
            }
        }

        @Override
        public void onResume() {
            // TODO Auto-generated method stub
            super.onResume();
            loadview();

        }
    }


    /**
     * 详情信息
     */
    public class MyDetailWeb extends BaseWebViewFragment {

        public MyDetailWeb() {
            super();
        }

        private EmptyLayout empty_loading;

        @Override
        public void init() {
            empty_loading = (EmptyLayout) findViewById(R.id.emptylayout);

            super.init();
        }

        @Override
        protected void onPreInitWebView() {
            if (StringUtils.equalsIgnoreCase(mEntityNameID, "attachement")) {
                mUrls = UrlManager.getManager().getEntityDetailNoHeaderUrl1(
                        mEntityId);
                mUrl = UrlManager.getManager().getEntityDetailNoHeaderUrl1(
                        mEntityId);
            } else {
                mUrls = UrlManager.getManager().getEntityDetailNoHeaderUrl(
                        mEntityId);
                mUrl = UrlManager.getManager().getEntityDetailNoHeaderUrl(
                        mEntityId);
            }

        }

        // 标识刷新次数
        int biaoshi = 1;

        @Override
        protected void startProgressDialog() {
            empty_loading.setVisibility(View.VISIBLE);
            empty_loading.loading();
            mWebView.setWebViewClient(new WebViewClient() {
                @Override
                public void onPageFinished(WebView view, String url) {
                    super.onPageFinished(view, url);
                }
            });
            mWebView.addJavascriptInterface(this, "JsInterface");

            mWebView.setWebViewClient(new WebViewClient() {

                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    if (url.endsWith("m=detail") || url.endsWith("m=detail4Native")) {
                        int start = url.indexOf("=") + 1;
                        int end = 0;
                        if (url.endsWith("m=detail")) {
                            end = url.indexOf("m=detail") -1;
                        }
                        if (url.endsWith("m=detail4Native")) {
                            end = url.indexOf("m=detail4Native") - 1;
                        }
                        String ids = url.substring(start,end);
                        Intent intent = new Intent(getActivity(),BeauInfoActivity.class);
                        intent.putExtra("web", ids);
                        startActivity(intent);

                    }
                    return false;
                }

                public void onPageFinished(WebView view, String url) {
                    mWebView.loadUrl("javascript:window.JsInterface.JsCallAndriod(document.documentElement.scrollHeight+'');");
                }
            });
        }


        @JavascriptInterface
        public void JsCallAndriod(final String height) {
            handler.post(new Runnable() {
                @Override
                public void run() {
                    length3 = mWebView.getHeight();
                    System.out.print("viewpager选中的item是mViewPager.getCurrentItem()" + length3);
                    if (mViewPager != null && mViewPager.getCurrentItem() == 1) {
                        length3 = mWebView.getHeight();
                        setHeight(length3);
                    }
                }
            });

        }

        @Override
        protected void stopProgressDialog() {
            empty_loading.setVisibility(View.GONE);
            mWebView.setVisibility(View.VISIBLE);
            int heighta = mWebView.getHeight();
            int a = heighta;
            int b = a;
            mmebView = mWebView;
        }

        @Override
        public int getLayoutId() {
            return R.layout.beau_info_detail;
        }

        public void refreshWeb() {
            biaoshi++;
            try {
                mWebView.setVisibility(View.GONE);
                mWebView.reload();
            } catch (Exception e) {
            }

        }

        @Override
        public void onResume() {
            // TODO Auto-generated method stub
            super.onResume();
            if (i == 2) {
                refreshWeb();
            }
            if (callLog != null && callLog.length() != 0) {
                refreshWeb();
            }

        }

    }

    private void initContainer() {
    }

    private PopupWindow popupWindow;


    /**
     * 初始化 事件类型
     */
    private void initChatterEventTypes() {
        mTypes = CacheManager.getInstance().getEventTypes();
        refreshEventTypes();
    }

    /**
     * 刷新事件类型了列表
     */
    private void refreshEventTypes() {
        new ChatterEngineImpl()
                .getChatterEventTypes(new ResultCallBack<List<ChatterEventType>>() {

                    @Override
                    public void onSuccess(List<ChatterEventType> types) {
                        mTypes = types;
                        CacheManager.getInstance().cacheEventTypes(types);
                    }

                    @Override
                    public void onFailure(ErrorInfo error) {
                        mTypes = CacheManager.getInstance().getEventTypes();
                    }
                });
    }

    private List<ChatterEventType> mTypes;

    private List<String> fillEventTypes() {
        if ("en".equals(mEns)) {
            List<String> list = new ArrayList<String>();
            if (ListUtils.isEmpty(mTypes)) {
                list.add("Report the record");
                list.add("To discuss posts");
                list.add("Sign in to visit");
                list.add("Record the phone");
                list.add("Record SMS");
                list.add("Record mail");
                list.add("Write a note");

                // list.add("@");
                if ((mEntityId.contains("001")) || (mEntityId.contains("004"))
                        || (mEntityId.contains("003"))) {
                    list.add("Check in");

                }
                list.add("task");
                return list;
            }
            for (ChatterEventType type : mTypes) {
                if (StringUtils.isBlank(type.codevalue)) {
                    continue;
                }
                list.add(type.codevalue);
            }
            for (int i = 0; i < list.size(); i++) {
                Log.d("liyyy", list.get(i));
            }
            // list.add("@");
            if ((mEntityId.contains("001")) || (mEntityId.contains("004"))
                    || (mEntityId.contains("003"))) {
                list.add("Check in");

            }
            list.add("task");
            return list;
        } else {
            List<String> list = new ArrayList<String>();
            if (ListUtils.isEmpty(mTypes)) {
                list.add("汇报记录");
                list.add("发讨论帖");
                list.add("签到拜访");
                list.add("记录电话");
                list.add("记录短信");
                list.add("记录邮件");
                list.add("写个备注");

                // list.add("@");
                if ((mEntityId.contains("001")) || (mEntityId.contains("004"))
                        || (mEntityId.contains("003"))) {
                    list.add("签到");

                }
                list.add("任务");
                return list;
            }
            for (ChatterEventType type : mTypes) {
                if (StringUtils.isBlank(type.key)) {
                    continue;
                }
                list.add(type.key);
            }
            for (int i = 0; i < list.size(); i++) {
                Log.d("liyyy", list.get(i));
            }
            // list.add("@");
            if ((mEntityId.contains("001")) || (mEntityId.contains("004"))
                    || (mEntityId.contains("003"))) {
                list.add("签到");

            }
            list.add("任务");
            return list;
        }

    }

    String whoid = "";
    String whoobj = "";
    String relateid = "";
    String relateobj = "";

    // 左下角点击事件
    protected void showPopu() {
        Log.d("mEntityId", "数据是" + mEntityId + atname);
        PopuWindowUtils.dissmiss(popupWindow);
        View view = LayoutInflater.from(mContext).inflate(
                R.layout.relevant_pop, null);
        ListView listView = (ListView) view.findViewById(R.id.relevant_popup);
        listView.setScrollbarFadingEnabled(true);
        List<String> list = fillEventTypes();
        final RelevantPopAdapter adapter2 = new RelevantPopAdapter(mContext,
                list);
        listView.setAdapter(adapter2);
        if (list.size() != 0 && list.size() >= 8) {
            popupWindow = new PopupWindow(view,
                    AppContext.getInstance().screenW * 2 / 5,
                    AppContext.getInstance().screenH / 2);
        } else {
            popupWindow = new PopupWindow(view,
                    AppContext.getInstance().screenW * 2 / 5,
                    AppContext.getInstance().screenH / 3);
        }

        popupWindow.setFocusable(true);
        popupWindow.setOutsideTouchable(true);
        // 这个是为了点击“返回Back”也能使其消失，并且并不会影响你的背景
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
//        popupWindow.showAsDropDown(leixings, 5, 3);
        listView.setOnItemClickListener(new OnItemClickListener() {
            private String relevantName;
            private String key;
            private String reuevantType;

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                                    long arg3) {
                if (popupWindow.isShowing()) {
                    popupWindow.dismiss();
                }
                String name = adapter2.getItem(arg2);
                if ("签到".equals(name)) {
                    Intent intent1 = new Intent(mContext, MapsActivity.class);
                    intent1.putExtra("beauinfo", "beau");
                    intent1.putExtra("name", name);
                    intent1.putExtra("id", mEntityId);
                    startActivity(intent1);
                } else if ("任务".equals(name)) {
                    String id = mEntityId;
                    // 潜在客户 004201700F462EEAr2Db 联系人 004201700F462EEAr2Db
                    String url = "";
                    if ((StringUtils.equalsIgnoreCase(mEntityNameID, "lead"))
                            || (StringUtils.equalsIgnoreCase(mEntityNameID,
                            "contact"))) {// 潜在客户 联系人
                        whoid = mEntityId;
                        whoobj = mEntityId.substring(0, 3);
                        url = UrlManager.getNewTaskOrSchedule_x(true, whoid,
                                whoobj);
                    } else {
                        relateid = mEntityId;
                        relateobj = mEntityId.substring(0, 3);
                        url = UrlManager.getNewTaskOrSchedule_y(true, relateid,
                                relateobj);
                    }
                    Log.d("request", "新建任务的" + url);
                    MonitorParam monitorParam = new MonitorParam(
                            new String[]{"m=save"},
                            WebSyncDefaultProxy.STEP_START,
                            new String[]{"m=query"}, true,
                            WebSyncDefaultProxy.STEP_OVERRIDEURL);
                    Intent intent = new Intent(mContext,
                            CloudWebViewActivity.class);
                    intent.putExtra(
                            "callback",
                            WebSyncDefaultProxy
                                    .creatDefaultProxy(
                                            ReceiverConstant.RECEIVE_REFRESH_SCHEDULE)
                                    .addMonitorParam(monitorParam)
                                    .addHomeMonitor());
                    intent.putExtra(ExtraConstant.EXTRA_URL, url);
                    startActivity(intent);
                } else {
                    try {
                        JsonObject jsonObject = mBeauInfo1.recordInformationList
                                .get(0);// 详情对象
                        relevantName = name + "【"
                                + GsonUtil.getStringByJson("name", jsonObject)
                                + "】";
                        AppContext.relevantName = GsonUtil.getStringByJson(
                                "name", jsonObject);
                    } catch (Exception e) {
                        relevantName = name;
                        e.printStackTrace();
                    }
                    reuevantType = name;
                    key = "1";
                    Intent intent = new Intent(mContext, EditorActivity.class);
                    intent.putExtra("urlId", mEntityId);
                    intent.putExtra("key", key);
                    intent.putExtra("CustomerActivity", relevantName);
                    intent.putExtra("reuevantType", reuevantType);
                    intent.putExtra("name", name);
                    intent.putExtra("from", "web");
                    startActivity(intent);
                }
            }
        });
    }

    /**
     * 刷新info 数据
     */
    public String jsonname;
//    public boolean is = true;

    private void refreshInfoData() {

        if (mEntityId == null || mEntityId.length() < 3) {
            return;
        }

        for (Map.Entry<String, String[]> entry : mEntityTypes.entrySet()) {
            if (StringUtils.equalsIgnoreCase(mEntityId.substring(0, 3), entry.getKey())) {
                requestKey = entry.getKey();
            }
        }
        String[] strings = mEntityTypes.get(requestKey);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < strings.length; i++) {
            sb.append(strings[i].trim());
            sb.append(",");
        }
        headerbar.beginProgress();
        Log.d("zoulejici", "走了几次");

        mBeauPresenter.getBeauInfo(mEntityId, mEntityNameID, sb.toString()
                .substring(0, sb.length() - 1));

        mBeauPresenter.getBeauInfoXG(mEntityId, mEntityNameID);
        Log.d("sbdata", sb.toString());
    }

    public String mIsShow;

    public void onEventMainThread(BeauInfoEvent event) {
        headerbar.completeProgress();
        if (event.isError()) {
            Toast.makeText(mContext, "获取详情失败", Toast.LENGTH_SHORT).show();
            getActivity().finish();
            return;
        }
        mBeauInfo1 = event.getData();
        JsonObject jsonObject = mBeauInfo1.recordInformationList.get(0);// 详情对象
        ViewUtils.setText(beau_name,
                GsonUtil.getStringByJson("name", jsonObject));
        mIsShow = GsonUtil.getStringByJson("isconvert", jsonObject);
        OwnerName = GsonUtil.getStringByJson("owneridccname", jsonObject);
        OwnerId = GsonUtil.getStringByJson("ownerid", jsonObject);
        if(ImageID == null || TextUtils.isEmpty(ImageID)){
            String tabimage = GsonUtil.getStringByJson("tabstyle", jsonObject);
            if(tabimage != null && !TextUtils.isEmpty(tabimage)){
                setImage(tabimage);
            }
        }
        if ("true".equals(mIsShow)) {
            SaveTemporaryData.mBeauInfoTui = "hintCall";
        } else if ("".equals(mIsShow)) {
            SaveTemporaryData.mBeauInfoTui = "showCall";
        } else if ("false".equals(mIsShow)) {
            SaveTemporaryData.mBeauInfoTui = "showCall";
        }
        mPersionName = GsonUtil.getStringByJson("name", jsonObject);
        listTitleName = GsonUtil.getStringByJson("name", jsonObject);
        mPersionNameIds = GsonUtil.getStringByJson("id", jsonObject);
        Log.d("liuyongjie", GsonUtil.getStringByJson("name", jsonObject));
        mJiLuName = GsonUtil.getStringByJson("name", jsonObject);
        name = GsonUtil.getStringByJson("name", jsonObject);
        List<MapKeyObj> fieldList = new ArrayList<MapKeyObj>();
        fieldList.clear();
        if (mEntityId.substring(0, 3).equals("003")) {// 联系人

            fieldList.add(new MapKeyObj("email", ""));
            fieldList.add(new MapKeyObj("khmcccname", ""));
            fieldList.add(new MapKeyObj("owneridccname", ""));
//            fieldList.add(new MapKeyObj("email", ""));
            beau_callll.setVisibility(View.VISIBLE);
            isCall = true;
            SaveTemporaryData.isCalling = false;
            beau_fenxiang.setVisibility(View.GONE);

        } else if (mEntityId.substring(0, 3).equals("002")) {// 业务机会
            fieldList.add(new MapKeyObj("khmcccname", ""));
            fieldList.add(new MapKeyObj("jsrq", ""));
            fieldList.add(new MapKeyObj("jine", ""));
            beau_callll.setVisibility(View.GONE);
            isCall = false;
            SaveTemporaryData.isCalling = false;
            beau_fenxiang.setVisibility(View.VISIBLE);

        } else if (mEntityId.substring(0, 3).equals("004")) {// 潜在客户
            fieldList.add(new MapKeyObj("company", ""));
            fieldList.add(new MapKeyObj("zhiwu", ""));
            fieldList.add(new MapKeyObj("dianhua", ""));
//            fieldList.add(new MapKeyObj("email", ""));
            beau_zhuanhuan.setVisibility(View.VISIBLE);
            beau_callll.setVisibility(View.GONE);
            if ("true".equals(mIsShow)) {
                beau_zhuanhuan.setVisibility(View.GONE);
                beau_callll.setVisibility(View.VISIBLE);
                SaveTemporaryData.mBeauInfoTui = "hintCall";
            } else if ("".equals(mIsShow)) {
                SaveTemporaryData.mBeauInfoTui = "showCall";
                beau_zhuanhuan.setVisibility(View.VISIBLE);
                beau_callll.setVisibility(View.GONE);
                SaveTemporaryData.mSmart = "add";
            } else if ("false".equals(mIsShow)) {
                SaveTemporaryData.mBeauInfoTui = "showCall";
                beau_zhuanhuan.setVisibility(View.VISIBLE);
                beau_callll.setVisibility(View.GONE);
                SaveTemporaryData.mSmart = "add";
            }
            isCall = true;
            SaveTemporaryData.isCalling = true;
            beau_fenxiang.setVisibility(View.GONE);
        } else if (mEntityId.substring(0, 3).equals("001")) {// 客户
            fieldList.add(new MapKeyObj("dianhua", ""));
            if (null != GsonUtil.getStringByJson("kddz", jsonObject) && !"".equals(GsonUtil.getStringByJson("kddz", jsonObject))) {
                fieldList.add(new MapKeyObj("kddz", ""));
            } else {
                fieldList.add(new MapKeyObj("fhdz", ""));
            }
            beau_callll.setVisibility(View.VISIBLE);
            isCall = true;
            SaveTemporaryData.isCalling = false;
            beau_fenxiang.setVisibility(View.GONE);
        } else if (mEntityId.substring(0, 3).equals("006")) {//市场活动  201100000004744Eb42l
            fieldList.add(new MapKeyObj("leixing", ""));
            fieldList.add(new MapKeyObj("zhuangtai", ""));
            fieldList.add(new MapKeyObj("ksrq", ""));
            beau_callll.setVisibility(View.GONE);
            isCall = true;
            SaveTemporaryData.isCalling = false;
            beau_fenxiang.setVisibility(View.VISIBLE);
        } else if (mEntityId.substring(0, 3).equals("007")) {//合同 201100000004911Amewy
            fieldList.add(new MapKeyObj("khmcccname", ""));
            fieldList.add(new MapKeyObj("zhuangtai", ""));
            fieldList.add(new MapKeyObj("htksrq", ""));
            beau_callll.setVisibility(View.GONE);
            isCall = true;
            SaveTemporaryData.isCalling = false;
            beau_fenxiang.setVisibility(View.VISIBLE);
        } else {
            fieldList.add(new MapKeyObj("owneridccname", ""));
            beau_callll.setVisibility(View.GONE);
            isCall = false;
            SaveTemporaryData.isCalling = false;
            beau_fenxiang.setVisibility(View.VISIBLE);
        }
        // 获取数据
        for (MapKeyObj mapKeyObj : fieldList) {
            String stringByJson = GsonUtil.getStringByJson(mapKeyObj.key,
                    jsonObject);

            mPname = stringByJson;
            mapKeyObj.value = stringByJson;
            Log.d("---value",mapKeyObj.value+"---");
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < fieldList.size(); i++) {
            MapKeyObj mapKeyObj = fieldList.get(i);
            Log.d("---cejiscna", mapKeyObj.key + ":::" + mapKeyObj.value);
            String value = mapKeyObj.value;
            if (!TextUtils.isEmpty(value)) {
                sb.append(mapKeyObj.value);
                if (i != fieldList.size() - 1) {
                    sb.append(" · ");
                }
            }
        }
        if (!TextUtils.isEmpty(sb.toString())) {
            ViewUtils.setText(beau_name_sub, sb.toString());
        }
        List<TabLabel> tabLabel = mBeauInfo1.tabLabel;
        title = tabLabel.get(0).tabName;
        ObjId = tabLabel.get(0).id;
        headerbar.setTitle(title);
        JsonObject jsonObject1 = mBeauInfo1.recordInformationList
                .get(0);// 详情对象
        jsonname = GsonUtil.getStringByJson("name", jsonObject1);
        onDismissLoadingDialog();
    }

    public void onEventMainThread(BeauInfoEventnew event) {
        headerbar.completeProgress();
        if (event.isError()) {
            Toast.makeText(mContext, "获取详情失败", Toast.LENGTH_SHORT).show();
            getActivity().finish();
            return;
        }
        mBeauInfo2 = event.getData();
        mBeauInfo4 = event.getData();
        fillDetails(true);
        onDismissLoadingDialog();


    }

    public void onEventMainThread(BeauEventList.BeauInfoTabEvent event) {
        headerbar.completeProgress();
        if (event.isError()) {
            return;
        }
        mBeauInfo3 = event.getData();
        checkviewpager = mBeauInfo3.defaultTabId;
        if (callLog != null && callLog.equals("addphone")) {
            checkviewpager = "0001";
        }
        setItemJudge();

    }

    private void setItemJudge() {
        if (checkviewpager.equals("0001")) {
            setRadioBtnb();
        }
        if (checkviewpager.equals("0002")) {
            setRadioBtna();
        }
        if (checkviewpager.equals("0003")) {
            setRadioBtnc();
        }
    }

    /**
     * 填充详情
     */
    private void fillDetails(boolean Isxiangguan) {

        if (mBeauInfo4 == null) {
            return;
        }
        if (!ListUtils.isEmpty(mBeauInfo4.recordIdButton)) {// 开始请求
            fillRelation();
        } else {
        }

        if (mBeauInfo2 == null) {
            return;
        }
        if (!ListUtils.isEmpty(mBeauInfo2.relationList)) {// 开始请求
            fillRelation();
        } else {
        }

    }

    private static class MapKeyObj {
        public String key;
        public String value;

        public MapKeyObj(String key, String value) {
            super();
            this.key = key;
            this.value = value;
        }

    }

    /**
     * 填充相关列表
     */
    int first = 1;

    private void fillRelation() {

        if (mBeauInfo2 == null || ListUtils.isEmpty(mBeauInfo2.relationList)) {
            return;
        }
        relationList = mBeauInfo2.relationList;
        aboutEvent.loadview();
    }


    @OnClick(R.id.beau_callll)
    public void clickPhone() {
        callPhone();
    }

    @OnClick(R.id.beau_zhuanhuan)
    public void zhuanhuan() {
        if (mBeauInfo4 == null) {
            return;
        }
        Intent intent = new Intent(mContext, ConvertCustomersActivity.class);
        Bundle menusend = new Bundle();
        menusend.putSerializable("mBeauInfo.recordIdButton", (Serializable) mBeauInfo4.recordIdButton);
        menusend.putString("mEntityNameID", mEntityNameID);
        menusend.putString("mEntityId", mEntityId);
        menusend.putString("oppName", title);
        intent.putExtra("OwnerName", OwnerName);
        intent.putExtra("OwnerId", OwnerId);
        intent.putExtras(menusend);

        startActivity(intent);

    }

    /**
     * 是不是 有详情
     *
     * @return
     */
    private boolean hasBeauInfoData() {
        Log.d("hasBeauInfoData", mBeauInfo1.recordInformationList.get(0)
                .toString());

        return mBeauInfo1 == null
                || ListUtils.isEmpty(mBeauInfo1.recordInformationList)
                || mBeauInfo1.recordInformationList.get(0) == null
                || ListUtils.isEmpty(mBeauInfo1.tabLabel);
    }


    @Override
    public void onDestroy() {
        if (mDynamicRefreshReceiver != null) {
            mContext.unregisterReceiver(mDynamicRefreshReceiver);
        }
        if (mSyncReceiver != null) {
            mContext.unregisterReceiver(mSyncReceiver);
        }
        EventEngine.uregister(this);
        super.onDestroy();
        VoiceMediaManager.release();
    }

    private PopupWindow mRightMenu;
    private String mEntityId;
    private String mEntityNameID;
    private String ImageID;
    private String title;
    private boolean isMeFollow = false;
    private String atname;
    private String mObjId;
    private String mObjName;

    @Bind(R.id.beau_info_edit_web)
    RelativeLayout beau_info_edit_web;

    private String requestKey = "other";

    /*
     * 切换数据
     */
    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        beau_info_edit_web.setVisibility(View.GONE);
//        relevent_dibu.setVisibility(View.GONE);
//        leixings.setVisibility(View.GONE);
        menu_foot.setVisibility(View.VISIBLE);
        switch (checkedId) {
            case R.id.beau_genzong:// 跟踪记录
                // if (mViewPager.getCurrentItem() != 1) {
//                topBarChange(0);
                mViewPager.setCurrentItem(0);

//                isnum = 2;
//                isxianshi = true;
//                setHeight(length2);
                break;
            case R.id.beau_detail:// 详情信息
//                topBarChange(1);
                mViewPager.setCurrentItem(1);
//                isnum = 1;
//                setHeight(length3);
                break;
            case R.id.beau_about:// 相关
//                topBarChange(2);
                mViewPager.setCurrentItem(2);
//                isnum = 3;
//                setHeight(length1);
                break;
        }

    }

    private void topBarChange(int pagerIndex) {
        //改变红线位置
        float fromX = lineWidth * (currentIndex);
        float toX = lineWidth * (pagerIndex);
        Animation animation = new TranslateAnimation(fromX, toX, 0, 0);
        animation.setFillAfter(true);
        animation.setDuration(300);
        checkLine.startAnimation(animation);
        currentIndex = pagerIndex;
    }


    @Override
    public void onClickLeft(View v) {
        // 事件
        if ("webview".equals(from)) {
            NewWebViewActivity.instance.finish();
            Intent intent = new Intent(mContext, NewWebViewActivity.class);
            intent.putExtra("MyPushMessageReceiver", "event");
            mShiJian = "p";
            startActivity(intent);
        } else if ("newwebview".equals(from)) {
            NewWebView.instance.finish();
            AppContext.urlString = UrlManager.getRootUrl()
                    + "/wx_taskquery.action?m=mywork";
            Intent intent = new Intent(mContext, NewWebView.class);
            // intent.putExtra("MyPushMessageReceiver", "event");
            mShiJian = "p";
            startActivity(intent);
        }
        // 任务
        if ("matter".equals(mShiJian)) {
            NewWebViewActivity.instance.finish();
            Intent intent2 = new Intent(mContext, NewWebViewActivity.class);
            intent2.putExtra("MyPushMessageReceiver", "task");
            from = "o";
            startActivity(intent2);
        }
        if (callLog != null && callLog.length() != 0) {
            Intent intent = new Intent(mContext, MainUIActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(intent);
        }
        getActivity().finish();
    }

    @Override
    public void onClickRight(View v) {
//		showRightPopu(false);
        EventEngine.post(new MenuToggleEventR(false, true));
    }

    /**
     * 显示popu 右边菜单
     *
     * @param isExp 是展开还是压缩
     */
    private void showRightPopu(boolean isExp) {
        if (mBeauInfo2 == null /* || ListUtils.isEmpty(mBeauInfo.relationCreateUrl) */) {
            return;
        }
        if (mRightMenu != null && mRightMenu.isShowing() && isExp) {// 展开
            int popuHeight = 0;
            LinearLayout subContainer = (LinearLayout) mRightMenu
                    .getContentView().findViewById(R.id.pop_holder);
            final int count = subContainer.getChildCount();
            for (int i = 0; i < count; i++) {
                View childAt = subContainer.getChildAt(i);
                childAt.setVisibility(i < count - 1 ? View.VISIBLE : View.GONE);
                popuHeight += ViewUtils.getViewMeasuredHeight(childAt);
            }
            mRightMenu.update(AppContext.screenW * 2 / 5,
                    Math.min(AppContext.screenH / 2, popuHeight));
        } else {
            PopuWindowUtils.dissmiss(mRightMenu);
            View contentView = (View) View.inflate(mContext,
                    R.layout.layout_popu_container, null);
            TextView textShareBtn = (TextView) contentView
                    .findViewById(R.id.textShareBtn);
            textShareBtn.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    setRadioBtnb();
                    if (mViewPager.getCurrentItem() != 0) {
                        mViewPager.setCurrentItem(0);
                        topBarChange(0);
//						setButtomUI(false);
                    }
                    if (mmebView != null) {
                        PopuWindowUtils.dissmiss(mRightMenu);

                        setShare();
                    } else {
                        setShare();
                    }
                    PopuWindowUtils.dissmiss(mRightMenu);
                }
            });
            LinearLayout subContainer = (LinearLayout) contentView
                    .findViewById(R.id.pop_holder);
            int popuHeight = 0;
            for (int i = 0; i < ListUtils.getSize(mBeauInfo2.relationCreateUrl) + 3; i++) {
                String qxgz = "取消关注";
                String gzjl = "关注记录";
                String scjl = "删除记录";
                String gdcz = "更多操作";
                if ("en".equals(mEns)) {
                    qxgz = "unsubscribe";
                    gzjl = "Attention record";
                    scjl = "Delete Record";
                    gdcz = "More operations";
                } else {
                    qxgz = "取消关注";
                    gzjl = "关注记录";
                    scjl = "删除记录";
                    gdcz = "更多操作";
                }

                View containerView = View.inflate(mContext,
                        R.layout.layout_pop_item, null);
                ImageView ivLogo = (ImageView) containerView
                        .findViewById(R.id.pop_item_image);
                ivLogo.setVisibility(View.GONE);
                TextView tvTitle = (TextView) containerView
                        .findViewById(R.id.pop_item_text);
                ImageView LIne = (ImageView) containerView
                        .findViewById(R.id.item_line);
                if (i < ListUtils.getSize(mBeauInfo2.relationCreateUrl)) {
                    ivLogo.setImageResource(R.drawable.entity_right_menu);
                    ObjMenu objMenu = mBeauInfo2.relationCreateUrl.get(i);
                    tvTitle.setText(objMenu.relationName);
                    Log.d("popwindows", objMenu.relationName);
                } else if (i == ListUtils.getSize(mBeauInfo2.relationCreateUrl)) {
                    ivLogo.setImageResource(R.drawable.entity_right_menu);
                    tvTitle.setText(isMeFollow ? qxgz : gzjl);
                } else if (i == ListUtils.getSize(mBeauInfo2.relationCreateUrl) + 1) {
                    ivLogo.setImageResource(R.drawable.entity_right_menu);
                    tvTitle.setText(scjl);
                } else if (i == ListUtils.getSize(mBeauInfo2.relationCreateUrl) + 2) {
                    ivLogo.setImageResource(R.drawable.entity_right_menu);
                    tvTitle.setText(gdcz);
                }
                popuHeight += ViewUtils.getViewMeasuredHeight(containerView);
                if (ListUtils.getSize(mBeauInfo2.relationCreateUrl) < 4) {
                    if (i == ListUtils.getSize(mBeauInfo2.relationCreateUrl) + 2) {
                        containerView.setVisibility(View.GONE);
                    }
                } else {
                    if (i > 3
                            && i != ListUtils
                            .getSize(mBeauInfo2.relationCreateUrl) + 2) {
                        containerView.setVisibility(View.GONE);
                    }
                }
                containerView.setOnClickListener(new MyMenuClick(i));
                subContainer.addView(containerView);
            }
            // 增加上 删除跟加载更多
            mRightMenu = new PopupWindow(contentView,
                    AppContext.screenW * 2 / 5,
                    LayoutParams.WRAP_CONTENT);
            mRightMenu.setBackgroundDrawable(new ColorDrawable(
                    Color.TRANSPARENT));
            mRightMenu.setFocusable(true);
            mRightMenu.showAsDropDown(headerbar.getRightLayout());
        }

    }

    // 右上角点击事件
    private class MyMenuClick implements OnClickListener {

        private int mPosition;

        public MyMenuClick(int position) {
            super();
            this.mPosition = position;
        }

        @Override
        public void onClick(View v) {
            if (mPosition < ListUtils.getSize(mBeauInfo2.relationCreateUrl)) {
                PopuWindowUtils.dissmiss(mRightMenu);
                ObjMenu objMenu = mBeauInfo2.relationCreateUrl.get(mPosition);
                if (StringUtils.equals(objMenu.relationUrl, "www.campaign.com")) {

                    JsonObject jsonObject = mBeauInfo2.recordInformationList
                            .get(0);// 详情对象
                    String name = GsonUtil.getStringByJson("name", jsonObject);
                    Log.d("popwindows", name + "www.campaign.com");
                    Intent intent = new Intent(mContext,
                            MarketActivityInfoActivity.class);
                    intent.putExtra(ExtraConstant.EXTRA_NAME, name);
                    intent.putExtra(ExtraConstant.EXTRA_ID, mEntityId);
                    startActivity(intent);
                } else {
                    Intent intent = new Intent(mContext,
                            CloudWebViewActivity.class);
                    Log.d("popwindows", "CloudWebViewActivity" + "跳轉小網頁");
                    intent.putExtra(
                            ExtraConstant.EXTRA_URL,
                            UrlManager.getManager().addReturnUrl(
                                    UrlManager.getManager().getUrlByRoot(
                                            objMenu.relationUrl)));
                    MonitorParam monitorParam = new MonitorParam(new String[]{
                            "m=save", "m=query", "type=remark"},
                            WebSyncDefaultProxy.STEP_START, new String[]{
                            "/WeiXin_index.action", "m=query"}, true,
                            WebSyncDefaultProxy.STEP_OVERRIDEURL);
                    intent.putExtra(
                            "callback",
                            WebSyncDefaultProxy
                                    .creatDefaultProxy(
                                            ReceiverConstant.RECEIVE_REFRESH)
                                    .addMonitorParam(monitorParam)
                                    .addHomeMonitor());
                    startActivity(intent);
                }
            } else if (mPosition == ListUtils
                    .getSize(mBeauInfo2.relationCreateUrl)) {// 跟随或者取消跟随
                Log.d("popwindows", "跟随或者取消跟随");
                PopuWindowUtils.dissmiss(mRightMenu);
                followEntity();
            } else if (mPosition == ListUtils
                    .getSize(mBeauInfo2.relationCreateUrl) + 1) {// 删除
                Log.d("shanchu", "删除");
                Log.d("popwindows", "删除");
                PopuWindowUtils.dissmiss(mRightMenu);
//				deleteEntity();
            } else if (mPosition == ListUtils
                    .getSize(mBeauInfo2.relationCreateUrl) + 2) {// 展开更多
                Log.d("popwindows", "展開更多");
                showRightPopu(true);
            }
        }
    }


    // 点击编辑
    @OnClick(R.id.beau_info_edit_web)
    public void clickEdit() {
        Intent intent = new Intent(mContext, CloudWebViewActivity.class);
        MonitorParam monitorParam = new MonitorParam(new String[]{"m=save",
                "m=edit"}, WebSyncDefaultProxy.STEP_START,
                new String[]{"/WeiXin_index.action"}, true,
                WebSyncDefaultProxy.STEP_OVERRIDEURL);
        intent.putExtra(
                "callback",
                WebSyncDefaultProxy
                        .creatDefaultProxy(ReceiverConstant.RECEIVE_REFRESH)
                        .addMonitorParam(monitorParam).addHomeMonitor());
        if (StringUtils.equalsIgnoreCase(mEntityNameID, "attachement")) {
            intent.putExtra(
                    ExtraConstant.EXTRA_URL,
                    UrlManager.getManager().addReturnUrl(
                            UrlManager.getManager().getEntityDetailEditUrl1(
                                    mEntityId)));
            startActivity(intent);
        } else {
            intent.putExtra(
                    ExtraConstant.EXTRA_URL,
                    UrlManager.getManager().addReturnUrl(
                            UrlManager.getManager().getEntityDetailEditUrl(
                                    mEntityId)));
            startActivity(intent);
        }

    }


    private SyncReceiver mSyncReceiver;

    private void initReceiver() {
        mSyncReceiver = new SyncReceiver();
        IntentFilter filter = new IntentFilter();
        filter.addAction(ReceiverConstant.RECEIVE_SYNC_WEB);
        filter.addAction(ReceiverConstant.RECEIVE_REFRESH);
        mContext.registerReceiver(mSyncReceiver, filter);
    }

    private class SyncReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
//			refreshInfoData();
            if (mDetailFragment != null) {
                // refreshInfoData();
                mDetailFragment.refreshWeb();
                setHeight(length3);
            }
            if (mDynamicFragment != null) {
                mDynamicFragment.onRefreshData();
            }
        }
    }

    @Override
    public void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        isresum = RunTimeManager.getInstance().getIsrem();
        if (isresum) {
            refreshInfoData();
        } else {
            RunTimeManager.getInstance().setIsrem(true);
        }
        VoiceMediaManager.resume();
        if ("call".equals(SaveTemporaryData.mSmart)) {
            callPhone();
        }


//        if ("保存业务成功".equals(SaveTemporaryData.mToastStr)) {
//
//            layoutTop.setVisibility(View.VISIBLE);
//            layoutBack.setVisibility(View.GONE);
//            toastHintContent.setText(SaveTemporaryData.mToastStr);
//            new AnimViewUtils().appearToast(layoutBack);
//            SaveTemporaryData.mToastStr = "";
//        }
        if ("保存成功".equals(SaveTemporaryData.saveWebView)) {
            i = 2;
            SaveTemporaryData.saveWebView = "";
        }
        MessageSetNCL();
    }


    public void callPhone() {
        String mobilePhone;
        if (hasBeauInfoData()) {
            Toast.makeText(mContext, getString(R.string.beau_info_fragment_no_phone), Toast.LENGTH_SHORT).show();
            return;
        }
        JsonObject jsonObject = mBeauInfo1.recordInformationList.get(0);
        List<TabLabel> tabLabel = mBeauInfo1.tabLabel;
        Log.d("tabLabel", mBeauInfo1.tabLabel.get(0).objectapiname);
        if ("Account".equals(tabLabel.get(0).objectapiname)) {// 客戶
            mobilePhone = GsonUtil.getStringByJson("dianhua", jsonObject);

        } else if ("Contact".equals(tabLabel.get(0).objectapiname)) {// 联系人
            mobilePhone = GsonUtil.getStringByJson("shouji", jsonObject);
            if (!StringUtils.isNotBlank(mobilePhone)) {
                mobilePhone = GsonUtil.getStringByJson("dianhua", jsonObject);
            }
            if (!StringUtils.isNotBlank(mobilePhone)) {
                mobilePhone = GsonUtil.getStringByJson("qtdh", jsonObject);
            }

        } else {// 潛在客戶
            mobilePhone = GsonUtil.getStringByJson("phone", jsonObject);
            if (!StringUtils.isNotBlank(mobilePhone)) {
                mobilePhone = GsonUtil.getStringByJson("dianhua", jsonObject);
            }
        }
        if (StringUtils.isNotBlank(mobilePhone)) {
            SystemUtils.sendCall(mContext, mobilePhone);
        } else {
            if ("en".equals(mEns)) {
                Toast.makeText(mContext, "No incoming telephone data", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(mContext, "未录入电话数据", Toast.LENGTH_SHORT).show();
            }
        }
        SaveTemporaryData.mSmart = "";
    }

    int lastVisiblItemPosition = 0;
    LinearLayout layoutscroll = null;

    class testscroll implements OnScrollListener {

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem,
                             int visibleItemCount, int totalItemCount) {
            if (firstVisibleItem > lastVisiblItemPosition) {
                // beau_information
                // 上滑
                layoutscroll = (LinearLayout) findViewById(R.id.beau_information);
                layoutscroll.setVisibility(View.GONE);
            } else if (firstVisibleItem < lastVisiblItemPosition) {
                // 下滑
                layoutscroll = (LinearLayout) findViewById(R.id.beau_information);
                layoutscroll.setVisibility(View.VISIBLE);
            }

            lastVisiblItemPosition = firstVisibleItem;

        }

        @Override
        public void onScrollStateChanged(AbsListView arg0, int arg1) {
            // TODO Auto-generated method stub

        }

    }

//    @Override
//    public void getUser(String userName) {
//        // TODO 待会就回调这个 在activity里回调
//        context_text.append(userName);
//    }


    /**
     * @param isShare
     */
    private void showDialog(boolean isShare) {
        View view = getActivity().getLayoutInflater().inflate(
                R.layout.sharepop, null);
        Dialog dialog = new Dialog(getActivity(),
                R.style.transparentFrameWindowStyle);
        dialog.setContentView(view, new LayoutParams(LayoutParams.FILL_PARENT,
                LayoutParams.WRAP_CONTENT));
        Window window = dialog.getWindow();
        // 设置显示动画
        window.setWindowAnimations(R.style.transparentFrameWindowStyle);
        WindowManager.LayoutParams wl = window.getAttributes();
        wl.x = 0;
        wl.y = getActivity().getWindowManager().getDefaultDisplay().getHeight();
        // 以下这两句是为了保证按钮可以水平满屏
        wl.width = LayoutParams.MATCH_PARENT;
        wl.height = LayoutParams.WRAP_CONTENT;

        // 设置显示位置
        dialog.onWindowAttributesChanged(wl);
        // 设置点击外围解散
        dialog.setCanceledOnTouchOutside(true);
        setShareListener(isShare, view, dialog);
        dialog.show();
    }


    /**
     * 设置分享点击事件
     *
     * @param isShare
     * @param dialog
     */
    public void setShareListener(boolean isShare, View view, final Dialog dialog) {
        // String mIshare = RunTimeManager.getInstance().getServerjiandang();
        if (!createFile()) {
            return;
        }

        TextView btnQq = (TextView) view.findViewById(R.id.btnQq);
        TextView btnqZone = (TextView) view.findViewById(R.id.btnqZone);
        TextView btnWeixin = (TextView) view.findViewById(R.id.btnWeixin);
        TextView btnWeixinQuan = (TextView) view
                .findViewById(R.id.btnWeixinQuan);
        TextView btnSina = (TextView) view.findViewById(R.id.btnSina);
        // isShare 测试中改为true
        // isShare = true;//测试分享，等正式用的时候要注释掉该行代码
        if (isShare) {
            btnQq.setVisibility(View.VISIBLE);
            btnqZone.setVisibility(View.VISIBLE);
            btnWeixin.setVisibility(View.VISIBLE);
            btnWeixinQuan.setVisibility(View.VISIBLE);
            btnSina.setVisibility(View.VISIBLE);
        } else {
            btnQq.setVisibility(View.GONE);
            btnqZone.setVisibility(View.GONE);
            btnWeixin.setVisibility(View.GONE);
            btnWeixinQuan.setVisibility(View.GONE);
            btnSina.setVisibility(View.GONE);
        }
        // QQ
        btnQq.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                PictureUtils.webviewContent2Png(getActivity(), mmebView);
                Intent intent = new Intent(getActivity(), DrawAct.class);
                intent.putExtra("share", "qq");
                intent.putExtra("Objame", title);
                intent.putExtra("mEntityId", mEntityId);
                intent.putExtra("mEntityNameID", ObjId);
                intent.putExtra("mJiLuName", mJiLuName);
                if (isQQClientAvailable(mContext)) {
                    startActivity(intent);
                } else {
                    Toast.makeText(mContext, "您没有安装QQ，请您下载QQ进行分享",
                            Toast.LENGTH_SHORT).show();
                }

                dialog.dismiss();
            }
        });
        // Qzone

        btnqZone.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                PictureUtils.webviewContent2Png(getActivity(), mmebView);
                Intent intent = new Intent();
                intent.setClass(getActivity(), DrawAct.class);
                intent.putExtra("share", "zone");
                intent.putExtra("Objame", title);
                intent.putExtra("mEntityId", mEntityId);
                intent.putExtra("mEntityNameID", ObjId);
                intent.putExtra("mJiLuName", mJiLuName);
                startActivity(intent);
                dialog.dismiss();
            }
        });
        // 微信好友

        btnWeixin.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                PictureUtils.webviewContent2Png(getActivity(), mmebView);
                Intent intent = new Intent();
                intent.setClass(getActivity(), DrawAct.class);
                intent.putExtra("share", "wechat");
                intent.putExtra("Objame", title);
                intent.putExtra("mEntityId", mEntityId);
                intent.putExtra("mEntityNameID", ObjId);
                intent.putExtra("mJiLuName", mJiLuName);
                startActivity(intent);
                dialog.dismiss();
            }
        });
        // 微信朋友圈

        btnWeixinQuan.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                PictureUtils.webviewContent2Png(getActivity(), mmebView);
                Intent intent = new Intent();
                intent.setClass(getActivity(), DrawAct.class);
                intent.putExtra("share", "pengyouquan");
                intent.putExtra("Objame", title);
                intent.putExtra("mEntityId", mEntityId);
                intent.putExtra("mEntityNameID", ObjId);
                intent.putExtra("mJiLuName", mJiLuName);
                startActivity(intent);
                dialog.dismiss();
            }
        });
        // 新浪微博
        btnSina.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                PictureUtils.webviewContent2Png(getActivity(), mmebView);
                Intent intent = new Intent();
                intent.setClass(getActivity(), DrawAct.class);
                intent.putExtra("share", "sina");
                intent.putExtra("Objame", title);
                intent.putExtra("mEntityId", mEntityId);
                intent.putExtra("mEntityNameID", ObjId);
                intent.putExtra("mJiLuName", mJiLuName);
                startActivity(intent);
                dialog.dismiss();
            }
        });
        // 云信
        TextView btnYunXin = (TextView) view.findViewById(R.id.btnYunXin);
        btnYunXin.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                PictureUtils.webviewContent2Png(getActivity(), mmebView);
                Intent intent = new Intent();
                intent.setClass(getActivity(), DrawAct.class);
                intent.putExtra("share", "yunxin");
                intent.putExtra("pName", mTiles + " :" + mPersionName);
                intent.putExtra("Objame", title);
                intent.putExtra("mEntityId", mEntityId);
                intent.putExtra("mEntityNameID", ObjId);
                intent.putExtra("mJiLuName", mJiLuName);
                boolean loggedIn = EMChat.getInstance().isLoggedIn();

                if (loggedIn) {
                    startActivity(intent);
                } else {
                    Toast.makeText(mContext, "没有开通此服务，无法分享", Toast.LENGTH_LONG).show();
                }

                dialog.dismiss();
            }
        });
    }

    //相关
    public void setRadioBtnc() {
        RadioButton b = (RadioButton) findViewById(R.id.beau_about);
        mViewPager.setCurrentItem(2);
        topBarChange(2);
        b.setChecked(true);
        setHeight(length1);
    }

    //跟踪记录
    public void setRadioBtnb() {
        mViewPager.setCurrentItem(0);
        topBarChange(0);
        RadioButton b = (RadioButton) findViewById(R.id.beau_genzong);
        b.setChecked(true);
        setHeight(length2);
    }

    //详情信息
    public void setRadioBtna() {
        mViewPager.setCurrentItem(1);
        topBarChange(1);
        RadioButton b = (RadioButton) findViewById(R.id.beau_detail);
        b.setChecked(true);
        setHeight(length3);
    }

    private void setShare() {

        HttpUtils utils = new HttpUtils();
        RequestParams params = new RequestParams();
        params.addBodyParameter("binding", RunTimeManager.getInstance()
                .getServerBinding());
        params.addBodyParameter("serviceName", "getSharePermission");
        Log.d("request----", "分享权限 url   " + UrlManager.getInterfaceUrl()
                + "?binding=" + RunTimeManager.getInstance().getServerBinding()
                + "&" + "serviceName=" + "getSharePermission");

        utils.send(HttpMethod.POST, UrlManager.getInterfaceUrl(), params,
                new RequestCallBack<String>() {

                    @Override
                    public void onFailure(HttpException arg0, String arg1) {
                        // TODO Auto-generated method stub
                        Log.d("request----", "分享权限Failure。。。" + arg1);
                    }

                    @Override
                    public void onSuccess(ResponseInfo<String> arg0) {
                        // TODO Auto-generated method stub
                        String result = arg0.result;
                        Log.d("request----", "分享权限Success:     " + result);
                        try {
                            JSONObject obj = new JSONObject(result);
                            JSONObject ooi = obj.getJSONObject("data");
                            boolean isShare = ooi.optBoolean("isshare");
                            showDialog(isShare);

                        } catch (JSONException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }

                });

    }

    private boolean createFile() {
        String sdStatus = Environment.getExternalStorageState();
        if (!sdStatus.equals(Environment.MEDIA_MOUNTED)) { // 检测sd是否可用
            Toast.makeText(getActivity(), "SD卡不可用", Toast.LENGTH_SHORT).show();
            return false;
        }
        String fileDir = Environment.getExternalStorageDirectory().getPath()
                + "/example/";
        File file = new File(fileDir);
        if (!file.exists()) {
            file.mkdirs();
        }
        // String fileName = new Date().getTime() + ".jpg";
        String fileName = "liuyongjie" + ".jpg";
        String originCameraImgPath = fileDir + fileName;
        photoFile = new File(originCameraImgPath);
        return true;
    }

    // 这是测试是否存在语音
    public int getLeng(String file) {
        int i;
        File f = new File(file);
        if (f.exists() && f.isFile()) {
            i = (int) f.length();
        } else {
            i = 1111;
        }
        return i;
    }

    // amr转Base64
    public String encodeBase64File(String path) throws Exception {
        File file = new File(path);
        FileInputStream inputFile = new FileInputStream(file);
        byte[] buffer = new byte[(int) file.length()];
        inputFile.read(buffer);
        inputFile.close();
        return Base64.encodeToString(buffer, Base64.DEFAULT);
    }

    /**
     * 将base64字符解码保存文件
     *
     * @param base64Code
     * @param targetPath
     * @throws Exception
     */
    public static void decoderBase64File(String base64Code, File targetPath)
            throws Exception {
        byte[] buffer = new BASE64Decoder().decodeBuffer(base64Code);
        FileOutputStream out = new FileOutputStream(targetPath);
        out.write(buffer);
        out.close();

    }


    /**
     * 判断qq是否可用
     *
     * @param context
     * @return
     */
    public static boolean isQQClientAvailable(Context context) {
        final PackageManager packageManager = context.getPackageManager();
        List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);
        if (pinfo != null) {
            for (int i = 0; i < pinfo.size(); i++) {
                String pn = pinfo.get(i).packageName;
                if (pn.equals("com.tencent.mobileqq")) {
                    return true;
                }
            }
        }
        return false;
    }

    private Dialog loadingDialog;

    public void onShowLoadingDialog() {
        if (loadingDialog != null) {
            loadingDialog.dismiss();
            loadingDialog = null;
        }
        loadingDialog = Utils.createLoadingDialog(mContext, getResources()
                .getString(R.string.waiting_hint));
        loadingDialog.show();
    }

    public void onDismissLoadingDialog() {
        if (loadingDialog != null) {
            loadingDialog.dismiss();
            loadingDialog = null;
        }
    }

    private void followEntity() {
        new OtherPresenter().followRecord(mEntityId, isMeFollow,
                new RequestListener() {

                    @Override
                    public void onSuccess(Object arg0) {
                        isMeFollow = !isMeFollow;
                        Toast.makeText(mContext,
                                isMeFollow ? "关注成功" : "取消关注成功", Toast.LENGTH_SHORT).show();
                        RefreshEntiityListEvent event = new RefreshEntiityListEvent();
                        event.setOk(true);
                        event.setData(new String[]{mEntityId,
                                String.valueOf(isMeFollow)});
                        EventEngine.post(event);
                    }

                    @Override
                    public void onFailure(ErrorInfo arg0) {
                        String errormessage = arg0.getErrorMessage();
                        Toast.makeText(mContext, errormessage, Toast.LENGTH_SHORT).show();

                    }
                });
    }

    public void onEventMainThread(RefreshEntiityListEvent evnet) {
        if (!evnet.isOk()) {
            return;
        }
        isMeFollow = !isMeFollow;
    }

    public void onEventMainThread(PostShare evnet) {
        if (evnet.isshare) {
            setRadioBtnb();
            if (mViewPager.getCurrentItem() != 0) {
                mViewPager.setCurrentItem(0);
                topBarChange(0);
//				setButtomUI(false);
            }
            if (mmebView != null) {
                setShare();
            } else {
                setShare();
            }
        }
    }

    public void setHeight(final int height) {
        handler.post(new Runnable() {
            @Override
            public void run() {
                lp = new LinearLayout.LayoutParams(
                        LinearLayout.LayoutParams.MATCH_PARENT, height + 200);
                mViewPager.setLayoutParams(lp);
            }
        });
    }

    private void MessageSetNCL() {
        long messagenum = 0;
        messagenum = RunTimeManager.getInstance().getMessageNx();
        message_num_tz.setText(messagenum + "");

        if (messagenum > 0) {
            message_num_tz.setVisibility(View.VISIBLE);
            if (messagenum > 99) {
                message_num_tz.setVisibility(View.INVISIBLE);
                message_num_99.setVisibility(View.VISIBLE);
            }

        } else {
            message_num_tz.setVisibility(View.INVISIBLE);
            message_num_99.setVisibility(View.INVISIBLE);
        }

    }


    public void onEventMainThread(MessageNumX event) {

        message_num_tz.setText(event.messageNumX + "");
        if (event.messageNumX > 0) {
            message_num_tz.setVisibility(View.VISIBLE);
            if (event.messageNumX > 99) {
                message_num_tz.setVisibility(View.INVISIBLE);
                message_num_99.setVisibility(View.VISIBLE);
            }

        } else {
            message_num_tz.setVisibility(View.INVISIBLE);
            message_num_99.setVisibility(View.INVISIBLE);
        }

    }
}
